print('----欢迎使用BMI计算程序----')

search_count = 0  # 记录查询次数
incorrect_count = 0  # 记录不正确的查询次数

while True:
    name = input('请键入您的姓名:')

    try:
        height, weight = map(float, input("请输入身高(米)和体重(公斤)[逗号隔开]: ").split(','))
    except ValueError:
        print("输入格式错误，请重新输入")
        incorrect_count += 1  # 增加不正确的查询次数
        continue

    gender = input('请键入你的性别(f/m)')
    bmi = weight / (height ** 2)

    if bmi < 18.5:
        who, nat = "偏瘦", "偏瘦"
    elif 18.5 <= bmi < 24:
        who, nat = "正常", "正常"
    elif 24 <= bmi < 25:
        who, nat = "正常", "偏胖"
    elif 25 <= bmi < 28:
        who, nat = "偏胖", "偏胖"
    elif 28 <= bmi < 30:
        who, nat = "偏胖", "肥胖"
    else:
        who, nat = "肥胖", "肥胖"

    print("BMI 指标为:国际'{0}', 国内'{1}'".format(who, nat))

    import time

    nowtime = time.asctime(time.localtime(time.time()))

    if gender == 'f':
        print('感谢', name, '女士在', nowtime, '使用本程序,祝您身体健康!')
    elif gender == 'm':
        print('感谢', name, '先生在', nowtime, '使用本程序,祝您身体健康!')
    else:
        print("无效的性别，请重新输入")
        continue

    search_count += 1  # 增加查询次数

    user_input = input("输入 'y' 继续循环，输入 'n' 停止循环: ")
    if user_input == 'n':
        break
    elif user_input != 'y':
        print("无效的输入，请重新输入")

print("您一共进行了", search_count, "次查询")
print("其中不正确的查询次数为", incorrect_count, "次")
